﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;

namespace OauthProvider
{
    class BoundParameter
    {
        readonly OAuthContext _context;
        readonly string _name;

        public BoundParameter(string name, OAuthContext context)
        {
            _name = name;
            _context = context;
        }

        NameValueCollection Collection
        {
            get
            {
                if (_context.UseAuthorizationHeader) return _context.AuthorizationHeaderParameters;
                if (_context.RequestMethod != "GET") return _context.FormEncodedParameters;
                return _context.QueryParameters;
            }
        }

        public string Value
        {
            get { return Collection[_name]; }
            set
            {
                if (value == null)
                {
                    Collection.Remove(_name);
                }
                else
                {
                    Collection[_name] = value;
                }
            }
        }
    }
}
